import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import Client from '@/client'
  
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },{
    path: '/ForgetPassword',
    component: () => import('@/views/login/ForgetPassword'),
    hidden: true, meta: {
      title: '前台',
      type: "Client",

    },
  },

  {
    path: '/Register',
    component: () => import('@/views/Client/Register'),
    hidden: true,
    meta: {
      title: '前台',
      type: "Client",

    },
  },
  {
    path: '/404',

    component: () => import('@/views/404'),
    hidden: true,
    meta: {
      type: "foreground",
    },
  },


  { path: '*', redirect: '/', hidden: true }
]
export const constantHomeRoutes = [
  {
    path: '/Client/Index',
    component: Client,
    redirect: "/Client/Home",
    meta: {
      title: '前台',
      type: "Client",

    },
    children: [{
      path: '/Client/Home',
      component: () => import('@/views/Client/Home'),
      name: 'Home',
      hidden: true,
      meta: {
        type: "Client",
        title: '首页',

      }
    },{
      path: '/Client/MyUserInfo',
      component: () => import('@/views/Client/MyUserCenter/MyUserInfo'),
      name: 'ClientMyUserInfo',
      hidden: true,
      meta: {
        type: "Client",
        title: '我的个人信息',

      }
    }]
  },
]


export const asyncRoutes = [
 
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    meta: {
        icon: "el-icon-s-home",
      roles: [0, 2],
    },
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      name: 'dashboard',
      meta: {
        roles: [0, 2],
        icon: "el-icon-s-home",
        title: '控制台',
        noCache: true
      }
    }]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/Admin/UserList',
    meta: {
      title: '用户',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'UserList',
      component: () => import('@/views/Admin/UserList'),
      name: 'UserList',
      meta: {
        title: '用户',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/AppUser',
    component: Layout,
    redirect: '/Admin/AppUserList',
    meta: {
      title: '用户',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'AppUserList',
      component: () => import('@/views/Admin/AppUserList'),
      name: 'AppUserList',
      meta: {
        title: '用户',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/Bicycle',
    component: Layout,
    redirect: '/Admin/BicycleList',
    meta: {
      title: '自行车',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'BicycleList',
      component: () => import('@/views/Admin/BicycleList'),
      name: 'BicycleList',
      meta: {
        title: '自行车',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/CreditScore',
    component: Layout,
    redirect: '/Admin/CreditScoreList',
    meta: {
      title: '信用评分',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'CreditScoreList',
      component: () => import('@/views/Admin/CreditScoreList'),
      name: 'CreditScoreList',
      meta: {
        title: '信用评分',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/LineUpload',
    component: Layout,
    redirect: '/Admin/LineUploadList',
    meta: {
      title: '线路实时上报',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'LineUploadList',
      component: () => import('@/views/Admin/LineUploadList'),
      name: 'LineUploadList',
      meta: {
        title: '线路实时上报',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/OrderInfo',
    component: Layout,
    redirect: '/Admin/OrderInfoList',
    meta: {
      title: '订单',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'OrderInfoList',
      component: () => import('@/views/Admin/OrderInfoList'),
      name: 'OrderInfoList',
      meta: {
        title: '订单',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/RegionLayout',
    component: Layout,
    redirect: '/Admin/RegionLayoutList',
    meta: {
      title: '区域划分',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'RegionLayoutList',
      component: () => import('@/views/Admin/RegionLayoutList'),
      name: 'RegionLayoutList',
      meta: {
        title: '区域划分',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/VolumeRecord',
    component: Layout,
    redirect: '/Admin/VolumeRecordList',
    meta: {
      title: '优惠卷领取记录',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'VolumeRecordList',
      component: () => import('@/views/Admin/VolumeRecordList'),
      name: 'VolumeRecordList',
      meta: {
        title: '优惠卷领取记录',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/Volumes',
    component: Layout,
    redirect: '/Admin/VolumesList',
    meta: {
      title: '优惠卷',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'VolumesList',
      component: () => import('@/views/Admin/VolumesList'),
      name: 'VolumesList',
      meta: {
        title: '优惠卷',
        roles: [0],
        noCache: true
      }
    }]
  },




]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes, ...constantHomeRoutes, ...asyncRoutes]
})

const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
